const initialState = {
  profile: {} as IProfile,
  userInfo: {} as IUserInfo,
};

export type ActionType =
  | { type: 'user/saveUserInfo'; payload: IUserInfo }
  | { type: 'user/saveProfile'; payload: IProfile }
  | { type: 'user/clearInfo' };

const userReducer = (state = initialState, action: ActionType): typeof initialState => {
  switch (action.type) {
    case 'user/saveUserInfo':
      return { ...state, userInfo: action.payload };
    case 'user/saveProfile':
      return { ...state, profile: action.payload };

    case 'user/clearInfo':
      return {
        ...state,
        userInfo: {} as IUserInfo,
        profile: {} as IProfile,
      };
    default:
      return state;
  }
};

export default userReducer;

interface IUserInfo {
  id: string;
  name: string;
  photo: string;
  intro?: any;
  art_count: number;
  follow_count: number;
  fans_count: number;
  like_count: number;
}

export interface IProfile {
  id: string;
  photo: string;
  name: string;
  mobile: string;
  gender: number;
  birthday: string;
  intro?: any;
}
